package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itheima.dao.CheckItemDao;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.CheckItem;
import com.itheima.service.CheckItemService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Collections;
import java.util.List;

@Service
public class CheckItemServiceImpl implements CheckItemService {

    @Autowired
    private CheckItemDao checkItemDao;
    @Override
    public PageInfo<CheckItem> findPage(QueryPageBean queryPageBean) {
        //暂时：查询所有检查项
        PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());   //代替sql语句中的limit
        //直接调用dao
        List<CheckItem> checkItems = checkItemDao.findPage(queryPageBean.getQueryString());
        //把List转化为PageInfo
        PageInfo<CheckItem> pageInfo = new PageInfo<>(checkItems);

        return pageInfo;
    }

    @Override
    public void add(CheckItem checkItem) {
        checkItemDao.add(checkItem);
    }

    @Override
    public CheckItem findById(int id) {
        CheckItem checkItem = checkItemDao.findById(id);
        return checkItem;
    }

    @Override
    public void edit(CheckItem checkItem) {
        checkItemDao.edit(checkItem);
    }

    @Override
    public void delete(int id) {
        //1.删除中间表
        checkItemDao.deleteMid(id);
        //2.删除检查项表
        checkItemDao.deleteCheckItemById(id);
    }

    @Override
    public List<CheckItem> findAll() {
        List<CheckItem> checkItems =  checkItemDao.findAll();
        return checkItems;
    }
}
